Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Websocket streams #243

Merged
merged 31 commits into from
Oct 26, 2015
Merged

Websocket streams #243

merged 31 commits into from
Oct 26, 2015

Conversation

mdobson
Copy link
Contributor

@mdobson mdobson commented Oct 16, 2015

Adding a websocket link that conforms to the multiplex websocket protocol detailed here:

https://docs.google.com/document/d/1-vkl6o5PjdgsPACXEo80-sF9gPkK9JNIGKxZ8G-2rtM

AdamMagaluk and others added 26 commits September 30, 2015 15:36
… StreamTopic class which is returned in callback.
…er uses calypso-memory to for topic queries.
@mdobson
Copy link
Contributor Author

mdobson commented Oct 22, 2015

Currently this branch will not allow you to subscribe to _peer/connect and _peer/disconnect events.

@mdobson
Copy link
Contributor Author

mdobson commented Oct 22, 2015

Fixt ^^

},
{
rel: [rels.events],
href: env.helpers.url.path('/events').replace(/^http/, 'ws')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are a few things to watch out for when building these URLs, such as... is there a forwarded protocol? Is this an HTTP client connection or a SPDY client connection? See here:

var isForwardedProtocol = context.env.request.headers.hasOwnProperty('x-forwarded-proto') &&
['http', 'https'].indexOf(context.env.request.headers['x-forwarded-proto']) !== -1;
var isSpdy = !!context.env.request.isSpdy && !isForwardedProtocol;
var rootPath = env.helpers.url.path(loader.path);
var eventPath = isSpdy ? rootPath + '/events' : rootPath.replace(/^http/, 'ws') + '/events';

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1. Added a test case for this, and functionality to properly calculate.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Talked with @AdamMagaluk thinking that we actually remove this link for SPDY responses entirely. Currently this feature is only really going to work over websockets.

@kevinswiber
Copy link
Member

This is really cool stuff. Is any of this functionality exposed to the Zetta runtime or is it all C2Z/Z2Z API? To enable this inside apps and scouts, we could probably do something like:

module.exports = function(server) {
  var stream = server.createReadStream('*/led/*/state', { limit: 100 });
  stream.on('data', function(msg) {
    // awesome!
  });
};

@AdamMagaluk
Copy link
Collaborator

@kevinswiber Currently no, this PR just focuses on the ws side of things. But yes that would be great in the app.

AdamMagaluk added a commit that referenced this pull request Oct 26, 2015
@AdamMagaluk AdamMagaluk merged commit b1a7f21 into master Oct 26, 2015
@AdamMagaluk AdamMagaluk deleted the websocket-streams branch October 26, 2015 13:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants